package com.dongdongshop.controller;

import com.dongdongshop.common.AjaxResult;
import com.dongdongshop.common.PageResult;
import com.dongdongshop.common.ResultEnum;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbSellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("seller")
public class SellerController {
    Logger logger = LoggerFactory.getLogger(SellerController.class);
    @DubboReference
    private TbSellerService tbSellerService;

    /*商家管理页面跳转*/
    @RequestMapping("runSeller")
    public String runSeller(){
        return "admin/seller";
    }
    /*商家页面展示*/
    @RequestMapping("selectInfoLimitServer")
    @ResponseBody
    public PageResult<TbSeller> selectInfoLimitServer(TbSeller seller, @RequestParam(value = "pageNumber",defaultValue = "1") Integer pageNumber,
                                                      @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        PageResult<TbSeller> pageBean = tbSellerService.selectInfoLimitServer(seller,pageNumber, pageSize);
        return pageBean;
    }
    /*跳转seller_1.html页面*/
    @RequestMapping("runSeller_1")
    public String runSeller_1(){
        return "admin/seller_1";
    }
    /*更具id查询商家*/
    @RequestMapping("getTbSellerBySellerId")
    @ResponseBody
    public AjaxResult getTbSellerBySellerId(String sellerId){
        try {
            TbSeller seller   = tbSellerService.getTbSellerBySellerId(sellerId);
            if (seller != null){
                return AjaxResult.R(ResultEnum.SUCCESS).setData(seller);
            }
            return AjaxResult.R(ResultEnum.ERROR);
        }catch (Exception e){
            logger.error("更具id查询商家失败!错误详情:{}",e);
            return AjaxResult.R(ResultEnum.ERROR);
        }
    }
    /*商家审核状态修改*/
    @RequestMapping("statusSeller")
    @ResponseBody
    public AjaxResult statusSeller(TbSeller seller){
        try {
            int i   = tbSellerService.statusSeller(seller);
            if (i>0){
                return AjaxResult.R(ResultEnum.EXAMINE_YES);
            }
            return AjaxResult.R(ResultEnum.ERROR);
        }catch (Exception e){
            logger.error("商家审核失败!错误详情:{}",e);
            return AjaxResult.R(ResultEnum.EXAMINE_NO);
        }
    }
}
